{
 "cells": [
  {
   "cell_type": "markdown",
   "source": [
    "## 第一问:\n",
    "### 血肿扩张风险相关因素探索建模\n",
    "<P>a)请根据“表1”（字段：入院首次影像检查流水号，发病到首次影像检查时间间隔），“表2”（字段：各时间点流水号及对应的HM_volume），判断患者sub001至sub100发病后48小时内是否发生血肿扩张事件。\n",
    "结果填写规范：1是0否，填写位置：“表4”C字段（是否发生血肿扩张）。\n",
    "如发生血肿扩张事件，请同时记录血肿扩张发生时间。\n",
    "结果填写规范：如10.33小时，填写位置：“表4”D字段（血肿扩张时间）。\n",
    "是否发生血肿扩张可根据血肿体积前后变化，具体定义为：后续检查比首次检查绝对体积增加≥6 mL或相对体积增加≥33%</P>"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "outputs": [
    {
     "data": {
      "text/plain": "       ID         首次检查流水号  HM_volume  HM_ACA_R_Ratio  HM_MCA_R_Ratio  \\\n0  sub001  20161212002136      69714        0.000258        0.877112   \n1  sub002  20160406002131      47500        0.496000        0.180779   \n2  sub003  20160413000006      86396        0.053718        0.829078   \n3  sub004  20161215001667      45498        0.002242        0.002198   \n4  sub005  20161222000978      14832        0.000000        0.000000   \n\n   HM_PCA_R_Ratio  HM_Pons_Medulla_R_Ratio  HM_Cerebellum_R_Ratio  \\\n0        0.120148                 0.000000                    0.0   \n1        0.302316                 0.000000                    0.0   \n2        0.099681                 0.000197                    0.0   \n3        0.029100                 0.000374                    0.0   \n4        0.001146                 0.000337                    0.0   \n\n   HM_ACA_L_Ratio  HM_MCA_L_Ratio  ...  ED_ACA_R_Ratio.8  ED_MCA_R_Ratio.8  \\\n0        0.000000        0.000000  ...               NaN               NaN   \n1        0.003032        0.000000  ...               NaN               NaN   \n2        0.000000        0.000000  ...               NaN               NaN   \n3        0.163458        0.313618  ...               NaN               NaN   \n4        0.000202        0.413363  ...               NaN               NaN   \n\n   ED_PCA_R_Ratio.8  ED_Pons_Medulla_R_Ratio.8  ED_Cerebellum_R_Ratio.8  \\\n0               NaN                        NaN                      NaN   \n1               NaN                        NaN                      NaN   \n2               NaN                        NaN                      NaN   \n3               NaN                        NaN                      NaN   \n4               NaN                        NaN                      NaN   \n\n   ED_ACA_L_Ratio.8  ED_MCA_L_Ratio.8  ED_PCA_L_Ratio.8  \\\n0               NaN               NaN               NaN   \n1               NaN               NaN               NaN   \n2               NaN               NaN               NaN   \n3               NaN               NaN               NaN   \n4               NaN               NaN               NaN   \n\n   ED_Pons_Medulla_L_Ratio.8  ED_Cerebellum_L_Ratio.8  \n0                        NaN                      NaN  \n1                        NaN                      NaN  \n2                        NaN                      NaN  \n3                        NaN                      NaN  \n4                        NaN                      NaN  \n\n[5 rows x 208 columns]",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>ID</th>\n      <th>首次检查流水号</th>\n      <th>HM_volume</th>\n      <th>HM_ACA_R_Ratio</th>\n      <th>HM_MCA_R_Ratio</th>\n      <th>HM_PCA_R_Ratio</th>\n      <th>HM_Pons_Medulla_R_Ratio</th>\n      <th>HM_Cerebellum_R_Ratio</th>\n      <th>HM_ACA_L_Ratio</th>\n      <th>HM_MCA_L_Ratio</th>\n      <th>...</th>\n      <th>ED_ACA_R_Ratio.8</th>\n      <th>ED_MCA_R_Ratio.8</th>\n      <th>ED_PCA_R_Ratio.8</th>\n      <th>ED_Pons_Medulla_R_Ratio.8</th>\n      <th>ED_Cerebellum_R_Ratio.8</th>\n      <th>ED_ACA_L_Ratio.8</th>\n      <th>ED_MCA_L_Ratio.8</th>\n      <th>ED_PCA_L_Ratio.8</th>\n      <th>ED_Pons_Medulla_L_Ratio.8</th>\n      <th>ED_Cerebellum_L_Ratio.8</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>sub001</td>\n      <td>20161212002136</td>\n      <td>69714</td>\n      <td>0.000258</td>\n      <td>0.877112</td>\n      <td>0.120148</td>\n      <td>0.000000</td>\n      <td>0.0</td>\n      <td>0.000000</td>\n      <td>0.000000</td>\n      <td>...</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>sub002</td>\n      <td>20160406002131</td>\n      <td>47500</td>\n      <td>0.496000</td>\n      <td>0.180779</td>\n      <td>0.302316</td>\n      <td>0.000000</td>\n      <td>0.0</td>\n      <td>0.003032</td>\n      <td>0.000000</td>\n      <td>...</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>sub003</td>\n      <td>20160413000006</td>\n      <td>86396</td>\n      <td>0.053718</td>\n      <td>0.829078</td>\n      <td>0.099681</td>\n      <td>0.000197</td>\n      <td>0.0</td>\n      <td>0.000000</td>\n      <td>0.000000</td>\n      <td>...</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>sub004</td>\n      <td>20161215001667</td>\n      <td>45498</td>\n      <td>0.002242</td>\n      <td>0.002198</td>\n      <td>0.029100</td>\n      <td>0.000374</td>\n      <td>0.0</td>\n      <td>0.163458</td>\n      <td>0.313618</td>\n      <td>...</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>sub005</td>\n      <td>20161222000978</td>\n      <td>14832</td>\n      <td>0.000000</td>\n      <td>0.000000</td>\n      <td>0.001146</td>\n      <td>0.000337</td>\n      <td>0.0</td>\n      <td>0.000202</td>\n      <td>0.413363</td>\n      <td>...</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n    </tr>\n  </tbody>\n</table>\n<p>5 rows × 208 columns</p>\n</div>"
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 读取文件\n",
    "import pandas as pd\n",
    "df0 = pd.read_excel(\"F:/机器学习数据集/2023年中国研究生数学建模竞赛赛题/2023年中国研究生数学建模竞赛赛题/E题/竞赛发布数据/表2-患者影像信息血肿及水肿的体积及位置.xlsx\")\n",
    "df0[:5]"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-11T11:49:56.934288600Z",
     "start_time": "2023-10-11T11:49:56.507291100Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "outputs": [
    {
     "data": {
      "text/plain": "   HM_volume  HM_volume.1\n0      69714      74902.0\n1      47500      52271.0\n2      86396     106042.0\n3      45498      39877.0\n4      14832      24472.0",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>HM_volume</th>\n      <th>HM_volume.1</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>69714</td>\n      <td>74902.0</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>47500</td>\n      <td>52271.0</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>86396</td>\n      <td>106042.0</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>45498</td>\n      <td>39877.0</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>14832</td>\n      <td>24472.0</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 第一次随访\n",
    "df1 = df0.iloc[0:100,[2,25]]\n",
    "df1[:5]"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-11T11:54:58.999657900Z",
     "start_time": "2023-10-11T11:54:58.983624Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "outputs": [
    {
     "data": {
      "text/plain": "0     False\n1     False\n2     False\n3     False\n4      True\n      ...  \n95    False\n96    False\n97    False\n98     True\n99    False\nLength: 100, dtype: bool"
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import numpy as np\n",
    "disease_1 = (df1.iloc[:,1]-df1.iloc[:,0])/df1.iloc[:,0] >=0.33\n",
    "disease_1"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-11T11:50:03.776291600Z",
     "start_time": "2023-10-11T11:50:03.767294300Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "outputs": [
    {
     "data": {
      "text/plain": "   HM_volume  HM_volume.2\n0      69714      70952.0\n1      47500      47748.0\n2      86396     103263.0\n3      45498      16622.0\n4      14832      25477.0",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>HM_volume</th>\n      <th>HM_volume.2</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>69714</td>\n      <td>70952.0</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>47500</td>\n      <td>47748.0</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>86396</td>\n      <td>103263.0</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>45498</td>\n      <td>16622.0</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>14832</td>\n      <td>25477.0</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 第二次随访\n",
    "df2 = df0.iloc[0:100,[2,48]]\n",
    "df2[:5]"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-11T11:54:35.496214300Z",
     "start_time": "2023-10-11T11:54:35.479192400Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "outputs": [
    {
     "data": {
      "text/plain": "0     False\n1     False\n2     False\n3     False\n4      True\n      ...  \n95    False\n96    False\n97    False\n98     True\n99    False\nLength: 100, dtype: bool"
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "disease_2 = (df2.iloc[:,1]-df2.iloc[:,0])/df2.iloc[:,0]>=0.33\n",
    "disease_2"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-11T11:57:28.805305900Z",
     "start_time": "2023-10-11T11:57:28.799312Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "outputs": [
    {
     "data": {
      "text/plain": "0     False\n1     False\n2     False\n3     False\n4      True\n      ...  \n95    False\n96    False\n97    False\n98     True\n99    False\nLength: 100, dtype: bool"
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "disease =disease_2 | disease_1 # 两个列取交集\n",
    "disease"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-11T12:00:40.730617200Z",
     "start_time": "2023-10-11T12:00:40.717578800Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "outputs": [
    {
     "data": {
      "text/plain": "            入院首次检查时间点              随访1时间点              随访2时间点\n0 2016-12-12 23:32:54 2016-12-13 05:19:00 2016-12-18 09:09:24\n1 2016-04-06 21:21:03 2016-04-07 09:16:27 2016-04-09 15:34:22\n2 2016-04-13 01:18:17 2016-04-13 08:49:38 2016-04-14 14:54:02\n3 2016-12-15 22:53:41 2016-12-16 14:52:08 2016-12-19 09:44:24\n4 2016-12-22 13:18:48 2016-12-23 10:46:51 2016-12-26 10:15:23",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>入院首次检查时间点</th>\n      <th>随访1时间点</th>\n      <th>随访2时间点</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>2016-12-12 23:32:54</td>\n      <td>2016-12-13 05:19:00</td>\n      <td>2016-12-18 09:09:24</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>2016-04-06 21:21:03</td>\n      <td>2016-04-07 09:16:27</td>\n      <td>2016-04-09 15:34:22</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>2016-04-13 01:18:17</td>\n      <td>2016-04-13 08:49:38</td>\n      <td>2016-04-14 14:54:02</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>2016-12-15 22:53:41</td>\n      <td>2016-12-16 14:52:08</td>\n      <td>2016-12-19 09:44:24</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>2016-12-22 13:18:48</td>\n      <td>2016-12-23 10:46:51</td>\n      <td>2016-12-26 10:15:23</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "## 读取随访时间\n",
    "query_time = pd.read_excel(\"F:/机器学习数据集/2023年中国研究生数学建模竞赛赛题/2023年中国研究生数学建模竞赛赛题/E题/竞赛发布数据/附表1-检索表格-流水号vs时间.xlsx\",usecols=['入院首次检查时间点','随访1时间点','随访2时间点'])\n",
    "query_time[:5]"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-11T12:10:16.642789100Z",
     "start_time": "2023-10-11T12:10:16.257789400Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "outputs": [
    {
     "data": {
      "text/plain": "False"
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d1 = pd.Timestamp(year = 2020, month = 7, day = 21,\n",
    "                    hour = 0, minute = 0, second = 0,\n",
    "                    )\n",
    "\n",
    "d2 = pd.Timestamp(year = 2020, month = 7, day = 23,\n",
    "                    hour = 0, minute = 0, second = 0,\n",
    "                    )\n",
    "\n",
    "(query_time.iloc[47,2]-query_time.iloc[47,0]) <= (d2-d1)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-11T12:22:56.707719900Z",
     "start_time": "2023-10-11T12:22:56.691692800Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0      False\n",
      "1      False\n",
      "2       True\n",
      "3      False\n",
      "4      False\n",
      "       ...  \n",
      "157     True\n",
      "158    False\n",
      "159    False\n",
      "160    False\n",
      "161     True\n",
      "Length: 162, dtype: bool\n"
     ]
    },
    {
     "data": {
      "text/plain": "0      False\n1      False\n2      False\n3      False\n4      False\n       ...  \n157    False\n158    False\n159    False\n160    False\n161    False\nLength: 162, dtype: bool"
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "query_time_2_0=(query_time.iloc[:,2]-query_time.iloc[:,0])<=(d2-d1)\n",
    "print(query_time_2_0)\n",
    "disease_48 = disease_2 & query_time_2_0 # 取交集判断是否48h发生血肿\n",
    "disease_48"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-11T12:29:37.327588100Z",
     "start_time": "2023-10-11T12:29:37.288589900Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "outputs": [
    {
     "data": {
      "text/plain": "0      False\n1      False\n2      False\n3      False\n4       True\n       ...  \n157    False\n158    False\n159    False\n160    False\n161    False\nLength: 162, dtype: bool"
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 最终结果\n",
    "disease=disease_1 | disease_48 # 取并集\n",
    "disease"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-11T12:33:13.931340300Z",
     "start_time": "2023-10-11T12:33:13.918342700Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "outputs": [
    {
     "data": {
      "text/plain": "([[4, 21.4675],\n  [8, 39.38611111111111],\n  [16, 12.870277777777778],\n  [32, 24.813055555555554],\n  [35, 36.50111111111111],\n  [37, 14.809166666666666],\n  [47, 11.860833333333334],\n  [51, 44.903888888888886],\n  [56, 14.365833333333333],\n  [59, 23.226111111111113],\n  [69, 6.653333333333333],\n  [75, 14.493611111111111],\n  [76, 12.119444444444444],\n  [78, 26.84722222222222],\n  [80, 24.421666666666667],\n  [91, 9.924722222222222],\n  [94, 6.431666666666667],\n  [98, 14.672777777777778]],\n [[62, 46.87], [98, 39.529444444444444]])"
     },
     "execution_count": 68,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 计算时间\n",
    "# 第一次随访血肿\n",
    "time1_list = []\n",
    "for i,is_dis in enumerate(disease_1):\n",
    "    if is_dis:\n",
    "       time = query_time.iloc[i,1]-query_time.iloc[i,0]\n",
    "       time1_list.append([i,time.total_seconds()/3600])\n",
    "\n",
    "# 第二次血肿\n",
    "time2_list = []\n",
    "for i,is_dis in enumerate(disease_48):\n",
    "    if is_dis:\n",
    "       time = query_time.iloc[i,2]-query_time.iloc[i,0]\n",
    "       time2_list.append([i,time.total_seconds()/3600])\n",
    "time1_list,time2_list"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-11T12:52:52.864027400Z",
     "start_time": "2023-10-11T12:52:52.855034700Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "outputs": [
    {
     "data": {
      "text/plain": "39.529444444444444"
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "time2_list[1][1].total_seconds()/3600"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-11T12:48:14.600417300Z",
     "start_time": "2023-10-11T12:48:14.586415200Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "outputs": [
    {
     "data": {
      "text/plain": "[[4, 21.4675],\n [8, 39.38611111111111],\n [16, 12.870277777777778],\n [32, 24.813055555555554],\n [35, 36.50111111111111],\n [37, 14.809166666666666],\n [47, 11.860833333333334],\n [51, 44.903888888888886],\n [56, 14.365833333333333],\n [59, 23.226111111111113],\n [69, 6.653333333333333],\n [75, 14.493611111111111],\n [76, 12.119444444444444],\n [78, 26.84722222222222],\n [80, 24.421666666666667],\n [91, 9.924722222222222],\n [94, 6.431666666666667],\n [98, 14.672777777777778],\n [62, 46.87]]"
     },
     "execution_count": 69,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 合并time1_list与time2_list\n",
    "time1_list.append([62,46.87])\n",
    "time1_list\n",
    "# 修改disease\n",
    "disease[62] = True"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-11T12:56:00.355882100Z",
     "start_time": "2023-10-11T12:56:00.323900500Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "outputs": [
    {
     "data": {
      "text/plain": "  Unnamed: 0  90天mRS 数据集划分     入院首次影像检查流水号  年龄 性别  脑出血前mRS评分  高血压病史  卒中病史  \\\n0     sub001     4.0    训练  20161212002136  43  女          0      0     0   \n1     sub002     0.0    训练  20160406002131  58  男          0      1     0   \n2     sub003     5.0    训练  20160413000006  78  男          0      1     0   \n3     sub004     4.0    训练  20161215001667  70  男          2      1     1   \n4     sub005     3.0    训练  20161222000978  51  男          0      0     0   \n\n   糖尿病史  ...  饮酒史  发病到首次影像检查时间间隔       血压  脑室引流  止血治疗 降颅压治疗  降压治疗  镇静、镇痛治疗  \\\n0     0  ...    0            2.5   180/90     0     1     1     1        1   \n1     0  ...    0            3.0  199/120     0     1     1     1        0   \n2     0  ...    0            2.0  199/120     0     1     1     1        1   \n3     0  ...    0            1.0   186/99     0     1     1     1        0   \n4     0  ...    0            5.0   135/92     0     1     1     0        0   \n\n   止吐护胃  营养神经  \n0     1     1  \n1     1     1  \n2     1     1  \n3     0     0  \n4     1     1  \n\n[5 rows x 23 columns]",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>Unnamed: 0</th>\n      <th>90天mRS</th>\n      <th>数据集划分</th>\n      <th>入院首次影像检查流水号</th>\n      <th>年龄</th>\n      <th>性别</th>\n      <th>脑出血前mRS评分</th>\n      <th>高血压病史</th>\n      <th>卒中病史</th>\n      <th>糖尿病史</th>\n      <th>...</th>\n      <th>饮酒史</th>\n      <th>发病到首次影像检查时间间隔</th>\n      <th>血压</th>\n      <th>脑室引流</th>\n      <th>止血治疗</th>\n      <th>降颅压治疗</th>\n      <th>降压治疗</th>\n      <th>镇静、镇痛治疗</th>\n      <th>止吐护胃</th>\n      <th>营养神经</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>sub001</td>\n      <td>4.0</td>\n      <td>训练</td>\n      <td>20161212002136</td>\n      <td>43</td>\n      <td>女</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>...</td>\n      <td>0</td>\n      <td>2.5</td>\n      <td>180/90</td>\n      <td>0</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>sub002</td>\n      <td>0.0</td>\n      <td>训练</td>\n      <td>20160406002131</td>\n      <td>58</td>\n      <td>男</td>\n      <td>0</td>\n      <td>1</td>\n      <td>0</td>\n      <td>0</td>\n      <td>...</td>\n      <td>0</td>\n      <td>3.0</td>\n      <td>199/120</td>\n      <td>0</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>0</td>\n      <td>1</td>\n      <td>1</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>sub003</td>\n      <td>5.0</td>\n      <td>训练</td>\n      <td>20160413000006</td>\n      <td>78</td>\n      <td>男</td>\n      <td>0</td>\n      <td>1</td>\n      <td>0</td>\n      <td>0</td>\n      <td>...</td>\n      <td>0</td>\n      <td>2.0</td>\n      <td>199/120</td>\n      <td>0</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>sub004</td>\n      <td>4.0</td>\n      <td>训练</td>\n      <td>20161215001667</td>\n      <td>70</td>\n      <td>男</td>\n      <td>2</td>\n      <td>1</td>\n      <td>1</td>\n      <td>0</td>\n      <td>...</td>\n      <td>0</td>\n      <td>1.0</td>\n      <td>186/99</td>\n      <td>0</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>sub005</td>\n      <td>3.0</td>\n      <td>训练</td>\n      <td>20161222000978</td>\n      <td>51</td>\n      <td>男</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>...</td>\n      <td>0</td>\n      <td>5.0</td>\n      <td>135/92</td>\n      <td>0</td>\n      <td>1</td>\n      <td>1</td>\n      <td>0</td>\n      <td>0</td>\n      <td>1</td>\n      <td>1</td>\n    </tr>\n  </tbody>\n</table>\n<p>5 rows × 23 columns</p>\n</div>"
     },
     "execution_count": 67,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.read_excel('F:/机器学习数据集/2023年中国研究生数学建模竞赛赛题/2023年中国研究生数学建模竞赛赛题/E题/竞赛发布数据/表1-患者列表及临床信息.xlsx')\n",
    "df[:5]"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-11T12:52:06.234656700Z",
     "start_time": "2023-10-11T12:52:06.118684400Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "outputs": [
    {
     "data": {
      "text/plain": "    Unnamed: 0  90天mRS 数据集划分     入院首次影像检查流水号  年龄 性别  脑出血前mRS评分  高血压病史  卒中病史  \\\n0       sub001     4.0    训练  20161212002136  43  女          0      0     0   \n1       sub002     0.0    训练  20160406002131  58  男          0      1     0   \n2       sub003     5.0    训练  20160413000006  78  男          0      1     0   \n3       sub004     4.0    训练  20161215001667  70  男          2      1     1   \n4       sub005     3.0    训练  20161222000978  51  男          0      0     0   \n..         ...     ...   ...             ...  .. ..        ...    ...   ...   \n155     sub156     NaN   测试2  20200306000927  87  女          0      1     0   \n156     sub157     NaN   测试2  20201009003102  52  男          2      1     1   \n157     sub158     NaN   测试2  20200410001952  57  男          0      1     0   \n158     sub159     NaN   测试2  20200218000582  47  男          0      1     0   \n159     sub160     NaN   测试2  20200821002584  80  女          0      1     0   \n\n     糖尿病史  ...  发病到首次影像检查时间间隔       血压  脑室引流  止血治疗  降颅压治疗 降压治疗  镇静、镇痛治疗  止吐护胃  \\\n0       0  ...            2.5   180/90     0     1      1    1        1     1   \n1       0  ...            3.0  199/120     0     1      1    1        0     1   \n2       0  ...            2.0  199/120     0     1      1    1        1     1   \n3       0  ...            1.0   186/99     0     1      1    1        0     0   \n4       0  ...            5.0   135/92     0     1      1    0        0     1   \n..    ...  ...            ...      ...   ...   ...    ...  ...      ...   ...   \n155     0  ...            5.5  202/100     0     1      1    1        0     1   \n156     0  ...            0.5  180/110     1     0      1    1        1     1   \n157     0  ...            2.8  233/135     0     1      1    1        1     1   \n158     0  ...            3.0  183/122     0     1      1    1        1     1   \n159     1  ...            4.0   208/95     1     1      1    1        1     1   \n\n     营养神经  labels  \n0       1   False  \n1       1   False  \n2       1   False  \n3       0   False  \n4       1    True  \n..    ...     ...  \n155     1   False  \n156     1   False  \n157     1   False  \n158     1   False  \n159     1   False  \n\n[160 rows x 24 columns]",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>Unnamed: 0</th>\n      <th>90天mRS</th>\n      <th>数据集划分</th>\n      <th>入院首次影像检查流水号</th>\n      <th>年龄</th>\n      <th>性别</th>\n      <th>脑出血前mRS评分</th>\n      <th>高血压病史</th>\n      <th>卒中病史</th>\n      <th>糖尿病史</th>\n      <th>...</th>\n      <th>发病到首次影像检查时间间隔</th>\n      <th>血压</th>\n      <th>脑室引流</th>\n      <th>止血治疗</th>\n      <th>降颅压治疗</th>\n      <th>降压治疗</th>\n      <th>镇静、镇痛治疗</th>\n      <th>止吐护胃</th>\n      <th>营养神经</th>\n      <th>labels</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>sub001</td>\n      <td>4.0</td>\n      <td>训练</td>\n      <td>20161212002136</td>\n      <td>43</td>\n      <td>女</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>...</td>\n      <td>2.5</td>\n      <td>180/90</td>\n      <td>0</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>False</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>sub002</td>\n      <td>0.0</td>\n      <td>训练</td>\n      <td>20160406002131</td>\n      <td>58</td>\n      <td>男</td>\n      <td>0</td>\n      <td>1</td>\n      <td>0</td>\n      <td>0</td>\n      <td>...</td>\n      <td>3.0</td>\n      <td>199/120</td>\n      <td>0</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>0</td>\n      <td>1</td>\n      <td>1</td>\n      <td>False</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>sub003</td>\n      <td>5.0</td>\n      <td>训练</td>\n      <td>20160413000006</td>\n      <td>78</td>\n      <td>男</td>\n      <td>0</td>\n      <td>1</td>\n      <td>0</td>\n      <td>0</td>\n      <td>...</td>\n      <td>2.0</td>\n      <td>199/120</td>\n      <td>0</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>False</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>sub004</td>\n      <td>4.0</td>\n      <td>训练</td>\n      <td>20161215001667</td>\n      <td>70</td>\n      <td>男</td>\n      <td>2</td>\n      <td>1</td>\n      <td>1</td>\n      <td>0</td>\n      <td>...</td>\n      <td>1.0</td>\n      <td>186/99</td>\n      <td>0</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>False</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>sub005</td>\n      <td>3.0</td>\n      <td>训练</td>\n      <td>20161222000978</td>\n      <td>51</td>\n      <td>男</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>...</td>\n      <td>5.0</td>\n      <td>135/92</td>\n      <td>0</td>\n      <td>1</td>\n      <td>1</td>\n      <td>0</td>\n      <td>0</td>\n      <td>1</td>\n      <td>1</td>\n      <td>True</td>\n    </tr>\n    <tr>\n      <th>...</th>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n    </tr>\n    <tr>\n      <th>155</th>\n      <td>sub156</td>\n      <td>NaN</td>\n      <td>测试2</td>\n      <td>20200306000927</td>\n      <td>87</td>\n      <td>女</td>\n      <td>0</td>\n      <td>1</td>\n      <td>0</td>\n      <td>0</td>\n      <td>...</td>\n      <td>5.5</td>\n      <td>202/100</td>\n      <td>0</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>0</td>\n      <td>1</td>\n      <td>1</td>\n      <td>False</td>\n    </tr>\n    <tr>\n      <th>156</th>\n      <td>sub157</td>\n      <td>NaN</td>\n      <td>测试2</td>\n      <td>20201009003102</td>\n      <td>52</td>\n      <td>男</td>\n      <td>2</td>\n      <td>1</td>\n      <td>1</td>\n      <td>0</td>\n      <td>...</td>\n      <td>0.5</td>\n      <td>180/110</td>\n      <td>1</td>\n      <td>0</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>False</td>\n    </tr>\n    <tr>\n      <th>157</th>\n      <td>sub158</td>\n      <td>NaN</td>\n      <td>测试2</td>\n      <td>20200410001952</td>\n      <td>57</td>\n      <td>男</td>\n      <td>0</td>\n      <td>1</td>\n      <td>0</td>\n      <td>0</td>\n      <td>...</td>\n      <td>2.8</td>\n      <td>233/135</td>\n      <td>0</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>False</td>\n    </tr>\n    <tr>\n      <th>158</th>\n      <td>sub159</td>\n      <td>NaN</td>\n      <td>测试2</td>\n      <td>20200218000582</td>\n      <td>47</td>\n      <td>男</td>\n      <td>0</td>\n      <td>1</td>\n      <td>0</td>\n      <td>0</td>\n      <td>...</td>\n      <td>3.0</td>\n      <td>183/122</td>\n      <td>0</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>False</td>\n    </tr>\n    <tr>\n      <th>159</th>\n      <td>sub160</td>\n      <td>NaN</td>\n      <td>测试2</td>\n      <td>20200821002584</td>\n      <td>80</td>\n      <td>女</td>\n      <td>0</td>\n      <td>1</td>\n      <td>0</td>\n      <td>1</td>\n      <td>...</td>\n      <td>4.0</td>\n      <td>208/95</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>False</td>\n    </tr>\n  </tbody>\n</table>\n<p>160 rows × 24 columns</p>\n</div>"
     },
     "execution_count": 74,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df['labels'] =disease\n",
    "#df['times'] = time1_list[:,1]\n",
    "df"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-11T13:00:42.006217600Z",
     "start_time": "2023-10-11T13:00:41.966227600Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "outputs": [],
   "source": [
    "df.to_excel(\"F:/机器学习数据集/2023年中国研究生数学建模竞赛赛题/2023年中国研究生数学建模竞赛赛题/E题/竞赛发布数据/labels.xlsx\")"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-11T13:03:03.436222800Z",
     "start_time": "2023-10-11T13:03:02.178226300Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "outputs": [
    {
     "data": {
      "text/plain": "    0          1\n0   4  21.467500\n1   8  39.386111\n2  16  12.870278\n3  32  24.813056\n4  35  36.501111",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>0</th>\n      <th>1</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>4</td>\n      <td>21.467500</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>8</td>\n      <td>39.386111</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>16</td>\n      <td>12.870278</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>32</td>\n      <td>24.813056</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>35</td>\n      <td>36.501111</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 78,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_time1_list = pd.DataFrame(time1_list)\n",
    "df_time1_list[:5]"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-11T13:07:04.672022700Z",
     "start_time": "2023-10-11T13:07:04.658022400Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "outputs": [],
   "source": [
    "df_time1_list.to_excel(\"F:/机器学习数据集/2023年中国研究生数学建模竞赛赛题/2023年中国研究生数学建模竞赛赛题/E题/竞赛发布数据/第一题a问解答.xlsx\")"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-11T13:07:12.005330400Z",
     "start_time": "2023-10-11T13:07:11.940282600Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
